﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public  class MG1:Group
    {
        // Fields




        //开始时的年月日时分秒

        private int m_IBYR = DateTime.Now.Year;
        private int m_IBMO = DateTime.Now.Month;
        private int m_IBDY = DateTime.Now.Day;
        private int m_IBHR = 0;
        private int m_IBMIN = 0;
        private int m_IBSEC = 0;


        //结束的时间
        private int m_IEDY = DateTime.Now.Day;
        private int m_IEHR = 0;
        private int m_IEMIN = 0;
        private int m_IEMO = DateTime.Now.Month;
        private int m_IESEC = 0;
        private int m_IEYR = DateTime.Now.Year;

        //utc时区， PST = UTC-0800, MST = UTC-0700 , GMT = UTC-0000，CST = UTC-0600, EST = UTC-0500，无默认值
        private string m_ABTZ = "UTC+0800";



        //时间步长，必须是3600的倍数，单位是秒
        private int m_NSECDT = 3600;


        //运行类型， 0 = Computes wind fields only  1 = Computes wind fields and micrometeorological variables
        //IRTYPE must be 1 to run CALPUFF or CALGRID
        //默认值是1
        private int m_IRTYPE = 1;

        //是否计算光化学转化的变量，calgrid,T,F ,默认是转化
        private bool m_LCALGRD = true;



        //SETUP阶段之后，是否继续运行计算阶段，ITEST = 1 - STOPS program after SETUP phase，
        //ITEST = 2 - Continues with execution of
        // COMPUTATIONAL phase after SETUP


        private int m_ITEST = 2;



        //数据测试
        //0 = NO checks are made
        //1 = Technical options must conform to USEPA guidance
        //          IMIXH    -1       Maul-Carson convective mixing height
        //                            over land; OCD mixing height overwater
        //          ICOARE   0        OCD deltaT method for overwater fluxes
        //          THRESHL  0.0      Threshold buoyancy flux over land needed
        //                            to sustain convective mixing height growth
        //          ISURFT   > 0      Pick one representative station, OR
        //                   -2       in NOOBS mode (ITPROG=2) average all
        //                            surface prognostic temperatures to get
        //                            a single representative surface temp.
        //          IUPT     > 0      Pick one representative station, OR
        //                   -2       in NOOBS mode (ITPROG>0) average all surface
        //                            prognostic temperatures to get a single
        //                            representative surface temp.

        private int m_MREG = 0;


        //下面是未找到对应项的属性

        private int m_IRTYPELCALGRD = 2;

        public string GetStrGeneralparame()
        {
            string Str = "-------------------------------------------------------------------------------\r\nINPUT GROUP: 1 -- General run control parameters\r\n-------------------------------------------------------------------------------\r\n";
            string mEnd = "  !";
            return (Str + "! IBYR  =  " + this.IBYR.ToString() + mEnd + "\r\n! IBMO  =  " + this.IBMO.ToString() + mEnd + "\r\n! IBDY  =  " + this.IBDY.ToString() + mEnd + "\r\n! IBHR  =  " + this.IBHR.ToString() + mEnd + "\r\n! IBSEC =  " + this.IBSEC.ToString() + mEnd + "\r\n! IEYR  =  " + this.IEYR.ToString() + mEnd + "\r\n! IEMO  =  " + this.IEMO.ToString() + mEnd + "\r\n! IEDY  =  " + this.IEDY.ToString() + mEnd + "\r\n! IEHR  =  " + this.IEHR.ToString() + mEnd + "\r\n! IESEC =  " + this.IESEC.ToString() + mEnd + "\r\n! ABTZ= " + this.ABTZ + mEnd + "\r\n! NSECDT =  " + this.NSECDT.ToString() + mEnd + "\r\n! IRTYPE=  " + this.IRTYPE.ToString() + mEnd + "\r\n! LCALGRD = " + this.LCALGRD + mEnd + "\r\n! ITEST=  " + this.ITEST.ToString() + mEnd + "\r\n! MREG =   " + this.MREG.ToString() + mEnd + "\r\n!END!\r\n");
        }



        #region 属性封装
        // Properties
        /// <summary>
        /// 时区，中国区域为UTC+0800，GMT = UTC-0000  CST = UTC-0600, EST = UTC-0500
        /// </summary>
        public string ABTZ
        {
            get
            {
                return this.m_ABTZ;
            }
            set
            {
                this.m_ABTZ = value;
            }
        }


        /// <summary>
        /// 开始日期，日
        /// </summary>
        public int IBDY
        {
            get
            {
                return this.m_IBDY;
            }
            set
            {
                this.m_IBDY = value;
            }
        }
        /// <summary>
        /// 开始日期，时
        /// </summary>
        public int IBHR
        {
            get
            {
                return this.m_IBHR;
            }
            set
            {
                this.m_IBHR = value;
            }
        }
        /// <summary>
        /// 没用
        /// </summary>
        public int IBMIN
        {
            get
            {
                return this.m_IBMIN;
            }
            set
            {
                this.m_IBMIN = value;
            }
        }
        /// <summary>
        /// 开始日期，月
        /// </summary>
        public int IBMO
        {
            get
            {
                return this.m_IBMO;
            }
            set
            {
                this.m_IBMO = value;
            }
        }
        /// <summary>
        /// 开始日期，秒
        /// </summary>
        public int IBSEC
        {
            get
            {
                return this.m_IBSEC;
            }
            set
            {
                this.m_IBSEC = value;
            }
        }
        /// <summary>
        /// 开始日期，年
        /// </summary>
        public int IBYR
        {
            get
            {
                return this.m_IBYR;
            }
            set
            {
                this.m_IBYR = value;
            }
        }
        /// <summary>
        /// 结束日期，日
        /// </summary>
        public int IEDY
        {
            get
            {
                return this.m_IEDY;
            }
            set
            {
                this.m_IEDY = value;
            }
        }
        /// <summary>
        /// 结束日期，时
        /// </summary>
        public int IEHR
        {
            get
            {
                return this.m_IEHR;
            }
            set
            {
                this.m_IEHR = value;
            }
        }
        /// <summary>
        /// 没用
        /// </summary>
        public int IEMIN
        {
            get
            {
                return this.m_IEMIN;
            }
            set
            {
                this.m_IEMIN = value;
            }
        }
        /// <summary>
        /// 结束日期，月
        /// </summary>
        public int IEMO
        {
            get
            {
                return this.m_IEMO;
            }
            set
            {
                this.m_IEMO = value;
            }
        }
        /// <summary>
        /// 结束日期，秒
        /// </summary>
        public int IESEC
        {
            get
            {
                return this.m_IESEC;
            }
            set
            {
                this.m_IESEC = value;
            }
        }
        /// <summary>
        /// 结束日期，年
        /// </summary>
        public int IEYR
        {
            get
            {
                return this.m_IEYR;
            }
            set
            {
                this.m_IEYR = value;
            }
        }


        /// <summary>
        /// 运行类型，0： 只计算风场；1：计算风场和气象参数。得到calpuff所需的风场，必须等于1。
        /// </summary>
        public int IRTYPE
        {
            get
            {
                return this.m_IRTYPE;
            }
            set
            {
                this.m_IRTYPE = value;
            }
        }
        /// <summary>
        /// 气象场选项，只控件界面表现与 IRTYPE 字段组合使用
        /// </summary>
        public int IRTYPELCALGRD
        {
            get
            {
                return this.m_IRTYPELCALGRD;
            }
            set
            {
                this.m_IRTYPELCALGRD = value;
            }
        }
        /// <summary>
        /// 停止程序运行的标志，用以检查模型输入
        /// </summary>
        public int ITEST
        {
            get
            {
                return this.m_ITEST;
            }
            set
            {
                this.m_ITEST = value;
            }
        }
        /// <summary>
        /// 计算Calgrid和CALPUFF需要的特殊数据，例如3d场中的,LCALGRD在运行 CALGRID 或者在calpuff中运用子网格尺度的复杂地形是，必须等于“T"。
        /// </summary>
        public bool LCALGRD
        {
            get
            {
                return this.m_LCALGRD;
            }
            set
            {
                this.m_LCALGRD = value;
            }
        }
        /// <summary>
        /// 检查模型选项是否符合EPA常规选项，在中国运用时建议设置为不检查
        /// </summary>
        public int MREG
        {
            get
            {
                return this.m_MREG;
            }
            set
            {
                this.m_MREG = value;
            }
        }
        /// <summary>
        /// 模型运转时间步长，单位秒,默认3600
        /// </summary>
        public int NSECDT
        {
            get
            {
                return this.m_NSECDT;
            }
            set
            {
                this.m_NSECDT = value;
            }
        }


        #endregion


        public  string WriteToGroup()
        {
            string ResultStr = "", TempStr;

            TempStr = "INPUT GROUP: 1 -- General run control parameters" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBYR = " + IBYR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBMO = " + IBMO.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBDY = " + IBDY.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBHR = " + IBHR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBSEC = " + IBSEC.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEYR = " + IEYR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEMO = " + IEMO.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEDY = " + IEDY.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEHR = " + IEHR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IESEC = " + IESEC.ToString() + " !" + "\r\n";
            ResultStr += TempStr;
            ResultStr += "! ABTZ= " + this.ABTZ + " !" + "\r\n";
            TempStr = "Length of modeling time-step (seconds)" + "\r\n";
            ResultStr += TempStr;

            TempStr = "Must divide evenly into 3600 (1 hour)" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! NSECDT = " + NSECDT.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IRTYPE = " + IRTYPE.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "Compute special data fields required" + "\r\n";
            ResultStr += TempStr;

            TempStr = "by CALGRID (i.e., 3-D fields of W wind" + "\r\n";
            ResultStr += TempStr;

            TempStr = "components and temperature)" + "\r\n";
            ResultStr += TempStr;

            TempStr = "in additional to regular" + "\r\n";
            ResultStr += TempStr;

            if (LCALGRD == true)
                TempStr = "! LCALGRD = " + "T" + " !" + "\r\n";
            else
                TempStr = "! LCALGRD = " + "F" + " !" + "\r\n";
            ResultStr += TempStr;

            //TempStr = "Flag to stop run after" + "\r\n";
            //ResultStr += TempStr;

            TempStr = "! ITEST = " + ITEST.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! MREG = " + MREG.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "!END " + "!" + "\r\n";
            ResultStr += TempStr;

            TempStr = StrWriter.GetCLine();
            ResultStr += TempStr;



            return ResultStr;


        }

        public  void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {
                if (m_dic.Key == "ABTZ")
                {
                    this.ABTZ = m_dic.Value;
                }
                //if (m_dic.Key == "fTHD")
                //{
                //    this.fTHD = Convert.ToInt32 ( m_dic.Value);
                //}
                if (m_dic.Key == "IBDY")
                {
                    this.IBDY = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBHR")
                {
                    this.IBHR = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBMIN")
                {
                    this.IBMIN = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBMO")
                {
                    this.IBMO = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBSEC")
                {
                    this.IBSEC = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBYR")
                {
                    this.IBYR = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IEDY")
                {
                    this.IEDY = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IEHR")
                {
                    this.IEHR = Convert.ToInt32(m_dic.Value);
                }
                //
                if (m_dic.Key == "IEMIN")
                {
                    this.IEMIN = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IEMO")
                {
                    this.IEMO = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IESEC")
                {
                    this.IESEC = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IEYR")
                {
                    this.IEYR = Convert.ToInt32(m_dic.Value);
                }
                //if (m_dic.Key == "IndexNPSTA")
                //{
                //    this.IndexNPSTA = Convert.ToInt32(m_dic.Value);
                //}
                if (m_dic.Key == "IRTYPE")
                {
                    this.IRTYPE = Convert.ToInt32(m_dic.Value);
                }
                //if (m_dic.Key == "IRTYPELCALGRD")
                //{
                //    this.IRTYPELCALGRD = Convert.ToInt32(m_dic.Value);
                //}
                if (m_dic.Key == "ITEST")
                {
                    this.ITEST = Convert.ToInt32(m_dic.Value);
                }
                //bool
                if (m_dic.Key == "LCALGRD")
                {
                    if (m_dic.Value == "T")
                    {
                        this.LCALGRD = true;
                    }
                    else
                    {
                        this.LCALGRD = false;
                    }

                }
                if (m_dic.Key == "MREG")
                {
                    this.MREG = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NSECDT")
                {
                    this.NSECDT = Convert.ToInt32(m_dic.Value);
                }

                //if (m_dic.Key == "TxtCount")
                //{
                //    this.TxtCount = Convert.ToInt32 ( m_dic.Value);
                //}
            }

        }
    }
}
